from django.db import models
from django.contrib.auth.models import User
from grades.models import Grades


# Create your models here.
GENDER_CHOICES = [
    ('男', '男'),
    ('女', '女'),
]

class Teacher(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='teacher')
    teacher_name = models.CharField(max_length=50, verbose_name='老师姓名')
    phone_number = models.CharField(max_length=11, unique=True, verbose_name='手机号')
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES, verbose_name='性别')
    birthday = models.DateField(verbose_name='出生日期', help_text='格式例如：2020-05-01') 
    # 老师（班主任）就是一个人管理一个班级，所以是一对一 models.DO_NOTHING 当老师被删除时，不会去自动删除管理的班级（也就是数据库不会自动处理关联记录）
    grade = models.OneToOneField(Grades, on_delete=models.DO_NOTHING, verbose_name='管理班级')
    create_time = models.DateTimeField(auto_now_add=True,verbose_name='创建日期')

    def __str__(self) -> str:
        return self.teacher_name

    class Meta:
        db_table = "teacher"
        verbose_name_plural = "老师信息"
        verbose_name = "老师信息"
        ordering = ['-create_time']
        